Skip to content

Conversation

@fzaninotto
Copy link
Member

@fzaninotto fzaninotto commented Sep 8, 2025

Problem

The way useApplyDefaultValues and ArrayInput subscribe to the form context to check for dirty or error state force a full rerendering of all fields in a field array on each change. This is very harmful for performance.

Solution

react-hook-form v7.62.0 introduces a way to subscribe to form changes without triggering a rerender. We can therefore manage the dirty and error states by hand to avoid the rerender.

How to test

Open the console, change the value of one field. Only this field should rerender

Open the React profiler, update one value in the array input, check out the output: no rendering should rerender all fields.

Also check that the NumberInput works as expected (it passes a null value when empty):

## Problem

The way useApplyDefaultValues and ArrayInput subscribe to the form context to check for dirty or error state force a full rerendering of all fields in a field array on each change. This is very harmful for performance.

## Solution

react-hook-form v7.62.0 introduces a way to subscribe to form changes without triggering a rerender. We can therefore manage the dirty and error states by hand to avoid the rerender.
@djhi
Copy link
Collaborator

djhi commented Sep 9, 2025

For now, we're stuck until react-hook-form/react-hook-form#12815 is solved

@fzaninotto fzaninotto changed the title Speed up ArrayInput [blocked] Speed up ArrayInput Sep 9, 2025
@djhi djhi changed the title [blocked] Speed up ArrayInput Speed up ArrayInput Oct 20, 2025
@djhi djhi added RFR Ready For Review WIP Work In Progress and removed WIP Work In Progress RFR Ready For Review labels Oct 20, 2025
@djhi djhi added RFR Ready For Review and removed WIP Work In Progress labels Oct 21, 2025
@slax57 slax57 self-requested a review October 22, 2025 08:33
@slax57 slax57 added this to the 5.13.0 milestone Nov 5, 2025
@slax57 slax57 merged commit c6ef779 into next Nov 5, 2025
15 checks passed
@slax57 slax57 deleted the speed-up-arry-input branch November 5, 2025 13:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

RFR Ready For Review

Development

Successfully merging this pull request may close these issues.

4 participants